<template>
  <div class="register">
    <el-form ref="evaluateForm" :model="evaluateForm" :rules="registerRules" class="register-form">
      <h3 class="title">我要评价</h3>

      <el-form-item label="老师名字" prop="teacherName">

        <el-input v-model="evaluateForm.teacherName" type="text" auto-complete="off" :disabled="true">
        </el-input >
      </el-form-item>

      <el-form-item label="学生名字" prop="studentName">
        <el-input v-model="evaluateForm.studentName" type="text" auto-complete="off" placeholder="请输入你的真实姓名" :disabled="true">
          <svg-icon slot="prefix" icon-class="user" class="el-input__icon input-icon" />
        </el-input >
      </el-form-item>

      <el-form-item label="处理时间" prop="procesTime" >
        <el-date-picker clearable
                        v-model="evaluateForm.procesTime"
                        type="datetime"
                        value-format="yyyy-MM-dd HH:mm:ss"
                        placeholder="请选择预约时间"
                        style="width: 100%"
                        :disabled="true">
        </el-date-picker>
      </el-form-item>

      <el-form-item label="问题类型" prop="problemType">
        <el-select v-model="evaluateForm.problemType" placeholder="请选择问题类型" style="width: 100%">
          <el-option
            v-for="dict in dict.type.problem_type"
            :key="dict.value"
            :label="dict.label"
            :value="parseInt(dict.value)"
            :disabled="true"
          ></el-option>
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-rate
          v-model="value"
          show-text>
        </el-rate>
      </el-form-item>

      <el-form-item  prop="detail">
        <el-input v-model="evaluateForm.detail" type="textarea" placeholder="请评价" />
      </el-form-item>


      <el-form-item style="width:100%;">
        <el-button
          :loading="loading"
          size="medium"
          type="primary"
          style="width:100%;"
          @click.native.prevent="handleRegister"
        >
          <span v-if="!loading">提交评价</span>
          <span v-else>提 交 中...</span>
        </el-button>
      </el-form-item>
    </el-form>
    <!--  底部  -->
    <div class="el-register-footer">
      <span>Copyright © 2018-2022 ruoyi.vip All Rights Reserved.</span>
    </div>
  </div>
</template>

<script>
import {getAssistByCode} from "@/api/education/assist";
import {listTeacher} from "@/api/education/teacher";
import {addEvaluate} from "@/api/education/evaluate";

export default {
  name: "Help",
  dicts: ['problem_type'],
  data() {
    return {
      code:"",
      codeUrl: "",
      evaluateForm: {
        studentName: "",
        procesTime: "",
        problemType: "",
        teacherName: "",
        detail: ""
      },
      teachers:[],
      registerRules: {
        detail: [
          { required: true, trigger: "blur", message: "不能为空" }]
      },
      loading: false,
      captchaEnabled: true
    };
  },
  created() {
    this.getTeachers();
    this.code = window.location.href.substr(1).split("=")[1];
    this.getAssists();
  },
  methods: {
    handleRegister() {
      this.$refs.evaluateForm.validate(valid => {
        if (valid) {
          this.loading = true;
          addEvaluate(this.evaluateForm).then(res => {
            this.$alert("<font color='red'>评价成功</font>", '系统提示', {
              dangerouslyUseHTMLString: true,
              type: 'success'
            }).then(() => {
              this.$router.push("/evaluate");
            }).catch(() => {});
          })
        }
      });
    },
    getTeachers(){
      listTeacher().then(res =>{
        this.teachers = res.rows;
      })
    },
    getAssists(){
      console.log(this.code);
      getAssistByCode(this.code).then(res=>{
        this.evaluateForm = res.data;
        this.evaluateForm.procesTime = res.data.completionTime;
      })
    }
  }
};
</script>

<style rel="stylesheet/scss" lang="scss">
.register {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100%;
  background-image: url("../assets/images/login-background.jpg");
  background-size: cover;
}
.title {
  margin: 0px auto 30px auto;
  text-align: center;
  color: #707070;
}

.register-form {
  border-radius: 6px;
  background: #ffffff;
  width: 400px;
  padding: 25px 25px 5px 25px;
  .el-input {
    height: 38px;
    input {
      height: 38px;
    }
  }
  .input-icon {
    height: 39px;
    width: 14px;
    margin-left: 2px;
  }
}
.register-tip {
  font-size: 13px;
  text-align: center;
  color: #bfbfbf;
}
.register-code {
  width: 33%;
  height: 38px;
  float: right;
  img {
    cursor: pointer;
    vertical-align: middle;
  }
}
.el-register-footer {
  height: 40px;
  line-height: 40px;
  position: fixed;
  bottom: 0;
  width: 100%;
  text-align: center;
  color: #fff;
  font-family: Arial;
  font-size: 12px;
  letter-spacing: 1px;
}
.register-code-img {
  height: 38px;
}
</style>
